package ru.spbu.math.android.cbrf.model;

import java.util.Date;

/**
 * Model for keeping data
 * 
 * @author Svetlana Zemlyanskaya
 */

public class Rate {

	private RateType resource;
	private double value; // 29.4003 or something else
	private double difference;
	private Date date; // date

	public Rate() {
		resource = new RateType();
		value = 0;
		date = new Date();
	}

	public Rate(RateType resource, double value, double difference, Date date) {
		this.resource = resource;
		this.value = format(value);
		this.difference = format(difference); 
		this.date = date;
	}

	public String getName() {
		return resource.getName();
	}

	public StockItem getSource() {
		return resource.getSource();
	}

	public double getValue() {
		return value;
	}

	public StockItem getTarget() {
		return resource.getTarget();
	}

	public Date getDate() {
		return date;
	}

	public void setResource(RateType itemR) {
		resource = itemR;
	}
	
	public RateType getResource() {
		return resource;
	}

	public void setValue(double valueF) {
		value = format(valueF);
	}

	public void setDate(Date currDate) {
		date = currDate;
	}

	public void setDifference(double difference) {
		this.difference = format(difference);
	}

	public double getDifference() {
		return difference;
	}

	public String toString() {

		String str = "";
		str += "Source: " + resource.getSource().toString();
		str += "Target: " + resource.getTarget().toString();
		str += " Value: " + value;
		str += " Date: " + date;

		return str;
	}
	
	private double format(double x) {
		return Math.round(x * 100000) / 100000.0;
	}
}
